home *** CD-ROM | disk | FTP | other *** search
/ SVM Mac 58 / CD-ROM N°58.iso / navigateurs / Netscape Folder / chrome / navigator / content / default / openLocation.js < prev    next >
Encoding:
JavaScript  |  2000-04-19  |  4.2 KB  |  127 lines  |  [TEXT/MOSS]

  1. /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2.  *
  3.  * The contents of this file are subject to the Netscape Public
  4.  * License Version 1.1 (the "License"); you may not use this file
  5.  * except in compliance with the License. You may obtain a copy of
  6.  * the License at http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the License is distributed on an "AS
  9.  * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
  10.  * implied. See the License for the specific language governing
  11.  * rights and limitations under the License.
  12.  *
  13.  * The Original Code is Mozilla Communicator client code, released March
  14.  * 31, 1998.
  15.  *
  16.  * The Initial Developer of the Original Code is Netscape Communications
  17.  * Corporation. Portions created by Netscape are
  18.  * Copyright (C) 1998 Netscape Communications Corporation. All
  19.  * Rights Reserved.
  20.  *
  21.  * Contributor(s): Michael Lowe <michael.lowe@bigfoot.com>
  22.  */
  23.  
  24. var browser;
  25. var dialog;
  26.  
  27. function onLoad() {
  28.     dialog = new Object;
  29.     dialog.input     = document.getElementById( "dialog.input" );
  30.     dialog.help      = document.getElementById( "dialog.help" );
  31.     dialog.topWindow = document.getElementById( "dialog.topWindow" );
  32.     dialog.topWindowDiv = document.getElementById( "dialog.topWindowDiv" );
  33.     dialog.newWindow = document.getElementById( "dialog.newWindow" );
  34.     dialog.newWindowDiv = document.getElementById( "dialog.newWindowDiv" );
  35.     dialog.editNewWindow = document.getElementById( "dialog.editNewWindow" );
  36.   dialog.open            = document.getElementById("ok");
  37.     dialog.openWhereBox = document.getElementById( "dialog.openWhereBox" );
  38.  
  39.  
  40.     browser = window.arguments[0];
  41.  
  42.   if ( !browser ) {
  43.     // No browser supplied - we are calling from Composer
  44.     dialog.topWindow.checked = false;
  45.     dialog.editNewWindow.checked = true;
  46.  
  47.     dialog.topWindowDiv.setAttribute("style","display:none;");
  48.     var pNode = dialog.newWindowDiv.parentNode;
  49.     pNode.removeChild(dialog.newWindowDiv);
  50.     pNode.appendChild(dialog.newWindowDiv);
  51.   } else {
  52.     dialog.topWindow.checked = true;
  53.   }
  54.     doSetOKCancel(open, 0, 0, 0);
  55.  
  56.     moveToAlertPosition();
  57.     /* Give input field the focus. */
  58.     dialog.input.focus();
  59.  
  60.   // change OK to load
  61.   dialog.open.setAttribute("value", document.getElementById("openLabel").getAttribute("value"));
  62. }
  63.  
  64. function onTyping( key ) {
  65.    // Look for enter key...
  66.    if ( key != 13 ) {
  67.       // Check for valid input.
  68.       if ( dialog.input.value == "" ) {
  69.          // No input, disable ok button if enabled.
  70.          if ( !dialog.open.disabled ) {
  71.             dialog.open.setAttribute( "disabled", "" );
  72.          }
  73.       } else {
  74.          // Input, enable ok button if disabled.
  75.          if ( dialog.open.disabled ) {
  76.             dialog.open.removeAttribute( "disabled" );
  77.          }
  78.       }
  79.    }
  80. }
  81.  
  82. function open() {
  83.     if ( dialog.open.disabled || dialog.input.value == "" ) {
  84.         return false;
  85.     }
  86.  
  87.     var url = dialog.input.value;
  88.         
  89.     try {
  90.         if ( dialog.topWindow.checked ) {
  91.             // Open the URL.
  92.             browser.loadUrl( url );
  93.         } else if ( dialog.newWindow.checked ) {
  94.             /* User wants new window. */
  95.               window.opener.delayedOpenWindow("chrome://navigator/content/navigator.xul","all,dialog=no",url);
  96.         } else if ( dialog.editNewWindow.checked ) {
  97.               window.opener.delayedOpenWindow("chrome://editor/content", "chrome,all,dialog=no", url);
  98.         }
  99.     } catch( exception ) {
  100.         // XXX l10n
  101.         alert( "Error opening location." );
  102.         return false;
  103.     }
  104.  
  105.    window.close();
  106.    return false;
  107. }
  108.  
  109. function createInstance( progid, iidName ) {
  110.   var iid = eval( "Components.interfaces." + iidName );
  111.   return Components.classes[ progid ].createInstance( iid );
  112. }
  113.  
  114. function onChooseFile() {
  115.     // Get filespecwithui component.            
  116.     var fileSpec = createInstance( "component://netscape/filespecwithui", "nsIFileSpecWithUI" );
  117.     try {
  118.         fileSpec.parentWindow = window;
  119.         var url = fileSpec.chooseFile( document.getElementById("chooseFileTitle").getAttribute("value") );
  120.         fileSpec.parentWindow = null;
  121.         dialog.input.value = fileSpec.URLString;
  122.     }
  123.     catch( exception ) {
  124.         // Just a cancel, probably.
  125.     }
  126. }
  127.